const express = require('express');
const router = express.Router();
const DB = require('../config/mysql');
const ResponseCode = require('../utils/responseCode');
const { GET_ACTIVE_BANNERS } = require('../sql/banners.sql');

// 获取轮播图列表（公开接口）
router.get('/banners', async (req, res) => {
  try {
    const banners = await DB.query(GET_ACTIVE_BANNERS);
    
    if (!banners || banners.length === 0) {
      return res.json({
        code: ResponseCode.NO_DATA,
        message: '暂无轮播图数据'
      });
    }

    res.json({
      code: ResponseCode.SUCCESS,
      message: '获取成功',
      data: banners
    });
  } catch (error) {
    console.error('获取轮播图错误:', error);
    res.json({
      code: ResponseCode.SERVER_ERROR,
      message: '获取轮播图失败，请稍后重试'
    });
  }
});

// 这里可以添加其他不需要token验证的公共接口
// 例如：获取公共配置、获取系统公告等

module.exports = router; 